import 'package:flutter/material.dart';

typedef AIChatMsgBodyStaticBulletItemClick = void Function(int index);

class AIChatMsgBodyStaticBulletList extends StatelessWidget {
  final List<String> itemList;
  final AIChatMsgBodyStaticBulletItemClick? onItemClick;
  final String? cardTitle;
  const AIChatMsgBodyStaticBulletList(
      {super.key, required this.itemList, this.onItemClick, this.cardTitle});

  @override
  Widget build(BuildContext context) {
    return Card(
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(10))),
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
          child: Column(
            children: [
              if (cardTitle != null)
                Padding(
                    padding: const EdgeInsets.only(bottom: 2, left: 5),
                    child: Row(children: [
                      Text(cardTitle ?? '',
                          style: Theme.of(context)
                              .textTheme
                              .bodyLarge
                              ?.copyWith(fontWeight: FontWeight.w500)),
                      const Spacer()
                    ])),
              if (cardTitle != null)
                const Padding(
                    padding: EdgeInsets.symmetric(vertical: 8),
                    child: Divider(height: 1)),
              ...List.generate(itemList.length * 2 - 1, (i) {
                if (i.isOdd) {
                  return const Padding(
                    padding: EdgeInsets.symmetric(vertical: 8),
                    child: Divider(height: 1),
                  );
                }
                int index = i ~/ 2;
                return GestureDetector(
                    onTap: () {
                      if (onItemClick != null) {
                        onItemClick!(index);
                      }
                    },
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          margin: const EdgeInsets.only(top: 6),
                          width: 8,
                          height: 8,
                          decoration: BoxDecoration(
                            color:
                                Theme.of(context).textTheme.bodyMedium?.color,
                            shape: BoxShape.circle,
                          ),
                        ),
                        const SizedBox(width: 12),
                        Expanded(
                          child: Text(itemList[index]),
                        ),
                      ],
                    ));
              })
            ],
          ),
        ));
  }
}
